/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package customGuiControl;

import java.awt.Graphics;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import java.util.logging.Level;
import java.util.logging.Logger;
import presentation.proportional.gui;

/**
 *
 * @author maja
 */
public class TextPane extends JTextPane {
    private final String text;
    private int previousHeight=0;

    public TextPane (String text, boolean opaque, boolean editable){
        super();
        this.text=text;
        this.setText(text);
        this.setOpaque(opaque);
        this.setEditable(editable);
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        try {
            SimpleAttributeSet bSet = new SimpleAttributeSet();
            StyleConstants.setAlignment(bSet, StyleConstants.ALIGN_CENTER);
            StyleConstants.setFontFamily(bSet, "arial");
            StyleConstants.setFontSize(bSet, new Float((17f/80f)*this.getHeight()).intValue());
            StyleConstants.setSpaceAbove(bSet, 5f);
            StyleConstants.setLeftIndent(bSet, 20f);
            //StyleConstants.setBold(bSet, true);

            //this.setText(this.text);
            StyledDocument doc = this.getStyledDocument();
            if (this.previousHeight!=this.getHeight()){
                doc.setParagraphAttributes(0, text.length(), bSet, false);
                this.previousHeight=this.getHeight();
            }
        } catch (Exception ex) {
            Logger.getLogger(gui.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public void setBold(boolean flag){
        SimpleAttributeSet bSet = new SimpleAttributeSet();
        StyleConstants.setBold(bSet, flag);
        StyledDocument doc = this.getStyledDocument();
        doc.setParagraphAttributes(0, text.length(), bSet, false);
    }

}
